#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& x : a) cin >> x;
    int mx = *max_element(a.begin(), a.end());
    int mi = *min_element(a.begin(), a.end());
    //cout << mx << " " << mi << endl;
    if (n <= 2)
    {
        cout << n;
        return;
    }
    int ans = 2;
    if (a[0] != mx && a[n - 1] != mx) ans++;
    if (a[0] != mi && a[n - 1] != mi) ans++;
    cout << ans;
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}